<?php 

function updateQuery($tables, $primaryKeys){
		
	$postkeys = array_keys($_POST);
	
	// INITIALIZE ARRAYS
	$rows = array(mysql_fetch_array(mysql_query("SELECT * FROM $tables[0]"), MYSQL_ASSOC));
	$updateQueries = array("UPDATE $tables[0] SET ");
	
	// COMPLETE ARRAYS
	for($i = 1; $i < count($tables); $i++){
		$temp = mysql_fetch_array(mysql_query("SELECT * FROM $tables[$i]"), MYSQL_ASSOC);
		array_push($rows, $temp);
		array_push($updateQueries, "UPDATE $tables[$i] SET ");
	}
	
	foreach($postkeys as $k){
		$newValue = "'".$_POST[$k]."'";
		if(trim($_POST[$k]) == '') $newValue = 'NULL';
		
		for($i = 0; $i < count($tables); $i++)
			if(array_key_exists($k, $rows[$i]))
				$updateQueries[$i] = $updateQueries[$i]."$k=$newValue, ";
	}
	
	for($i = 0; $i < count($tables); $i++){
		$updateQueries[$i] = substr_replace($updateQueries[$i], ' ', strlen($updateQueries[$i])-2);	//REMOVES LAST COMMA BEFORE 'WHERE'
		$tempKeys = array_keys($rows[$i]);
		$compareKey = $tempKeys[0];
		$updateQueries[$i] = $updateQueries[$i]." WHERE $compareKey='$primaryKeys[$i]';";
		if (!mysql_query($updateQueries[$i])) echo "Save Failed: $updateQueries[$i] <br />" . mysql_error() . "<br /> <br />";
	}
	
}

?>